package com.qixin.modules.ea.controller;

import com.qixin.modules.ea.vo.TaskPageVo;
import com.qixin.modules.eaBasic.entity.ActivitiTask;
import com.qixin.modules.eaBasic.service.IEaTaskService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.EmptyUtil;
import org.jeecg.modules.activiti.entity.TaskVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @Author:wly
 * @Date:2021/9/18
 * @Describtion: 待办访问层
 */
@Api(tags="pc待办")
@RestController
@RequestMapping("/ea/task")
@Slf4j
public class TaskController {
    @Autowired
    private IEaTaskService iEaTaskService;

    /**
     * 查询待办列表
     *
     * @return Result
     */
    @AutoLog(value = "查询待办列表-查询")
    @ApiOperation(value="查询待办列表-查询", notes="查询待办列表-查询")
    @GetMapping(value = "/todolist")
    public Result<?> todolist(@RequestParam(name="page", defaultValue="1") Integer page,
                              @RequestParam(name="limit", defaultValue="10") Integer limit,
                              HttpServletRequest request) {
        TaskPageVo taskPageVo = new TaskPageVo();
        String formType = EmptyUtil.checkNull(request.getParameter("formType"));//单据类型
        String userId = EmptyUtil.checkNull(request.getParameter("userId"));//流程发起人id
        String billNo = EmptyUtil.checkNull(request.getParameter("billNo"));//单据编号

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId2 = sysUser.getId();
        taskPageVo.setUserid(userId2);      //当前用户
        taskPageVo.setPage(page);           //页码
        taskPageVo.setLimit(limit);         //页面大小
        taskPageVo.setForm_type(formType);
        taskPageVo.setApplyerId(userId);
        taskPageVo.setBillNo(billNo);

        Map<String,Object> resutlList = iEaTaskService.list(taskPageVo);
        return Result.OK(resutlList);
    }

    /**
     * 查询已办列表
     *
     * @return Result
     */
    @AutoLog(value = "查询已办列表-查询")
    @ApiOperation(value="查询已办列表-查询", notes="查询已办列表-查询")
    @GetMapping(value = "/donelist")
    public Result<?> donelist(@RequestParam(name="page", defaultValue="1") Integer page,
                              @RequestParam(name="limit", defaultValue="10") Integer limit,
                              HttpServletRequest request) {
        TaskPageVo taskPageVo = new TaskPageVo();
        String formType = EmptyUtil.checkNull(request.getParameter("formType"));//单据类型
        String userId = EmptyUtil.checkNull(request.getParameter("userId"));//流程发起人id
        String billNo = EmptyUtil.checkNull(request.getParameter("billNo"));//单据编号

        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        String userId2 = sysUser.getId();
        taskPageVo.setDb_status("1");    //设置已办状态
        taskPageVo.setUserid(userId2);      //当前用户
        taskPageVo.setPage(page);           //页码
        taskPageVo.setLimit(limit);         //页面大小
        taskPageVo.setForm_type(formType);  //单据类型
        taskPageVo.setApplyerId(userId);    //流程发起人id
        taskPageVo.setBillNo(billNo);       //单据编号

        Map<String,Object> resutlList = iEaTaskService.list(taskPageVo);
        return Result.OK(resutlList);
    }

}
